package p.ithorns.sample.aviator;

import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression;
import com.googlecode.aviator.runtime.JavaMethodReflectionFunctionMissing;

import java.io.IOException;

/**
 * HelloWorld
 *
 * @author HtL
 * @date 2025/3/19 10:07
 * @since 1.0.0
 */
public class HelloWorld {

    public static void main(String[] args) throws IOException {
        execute("hello.av");
        executeWithReflection("date.av");
    }

    static void execute(String script) throws IOException {
        Expression exp = AviatorEvaluator.getInstance().compileScript("examples/" + script, true);
        exp.execute();
    }

    /**
     * 基于反射调用
     */
    static void executeWithReflection(String script) throws IOException {
        AviatorEvaluator.setFunctionMissing(JavaMethodReflectionFunctionMissing.getInstance());
        execute(script);
    }

}